import { _decorator, BoxCollider2D, CameraComponent, Collider, Collider2D, Component, Contact2DType, Node, RigidBody, Sprite } from 'cc';
import { Constant } from '../AshFramework/Datas/Constant';
import { CameraController } from './CameraController';
import { Chariot } from './Chariot';
const { ccclass, property } = _decorator;

@ccclass('Terminus')
export class Terminus extends Component {
    @property(BoxCollider2D)
    Collider2D_0: BoxCollider2D = null;

    @property(BoxCollider2D)
    Collider2D_1: BoxCollider2D = null;

    @property
    HP: number = 100;

    protected onLoad(): void {
        this.Collider2D_0.on(Contact2DType.BEGIN_CONTACT, this.beginContact_0, this);
        this.Collider2D_1.on(Contact2DType.BEGIN_CONTACT, this.beginContact_1, this);
    }

    beginContact_0(selfCollider: Collider2D, otherCollider: Collider2D) {
        if (otherCollider.group === Constant.Group.chariot) {
            Chariot.Instance.dirX = 0;
            console.log(`玩家停止移动`);
        }
    }

    beginContact_1(selfCollider: Collider2D, otherCollider: Collider2D) {
        if (otherCollider.group === Constant.Group.chariot) {
            CameraController.Instance.isPause = true;
            console.log(`屏幕停止滚动`);
        }
    }

    beHit(harm) {
        this.HP -= harm;
        console.log(`被攻击！！`);
    }

}


